<?php ;
include_once('Smarty.class.php');
$main_smarty = new Smarty;

include('config.php');
include(mnminclude.'html1.php');
include(mnminclude.'link.php');
include(mnminclude.'smartyvariables.php');

if (empty($_GET['link_id']) || ! is_numeric($_GET['link_id'])) {
    echo 'bad link_id';
    die;
}

$qLinkId = $db->escape($_GET['link_id']);
$linkres = new Link;
$linkres->id = $qLinkId;
$linkres->read();

force_authentication();

if (! checklevel('god')) {
    echo 'not allowed';
    die;
}

totals_adjust_count($linkres->status, -1);

$db->query("DELETE FROM ".table_links
           ." WHERE link_id = ".$qLinkId);

$db->query("DELETE FROM ".table_votes
           ." WHERE vote_link_id = ".$qLinkId);

$db->query("DELETE FROM ".table_comments
           ." WHERE comment_link_id = ".$qLinkId);

$db->query("DELETE FROM ".table_tags
           ." WHERE tag_link_id = ".$qLinkId);

$db->query("DELETE FROM ".table_saved_links
           ." WHERE saved_link_id = ".$qLinkId);

$db->query("DELETE FROM ".table_trackbacks
           ." WHERE trackback_link_id = ".$qLinkId);

$author = $linkres->username();
$location = getmyurl('user_add_remove', $author, 'history');
header('Location: ' . $location);
